import { MapSchema, Schema, type } from '@colyseus/schema';
import { Player } from './Player';
import { Monster } from './Monster';
import { NPC } from './NPC';

/**
 * 地图房间状态
 */
export class MapRoomState extends Schema {
    @type('number') playerCount: number = 0; // 当前玩家数量
    @type({map: Monster}) monsters = new MapSchema<Monster>(); // 怪物列表
    @type({map: NPC}) npcs = new MapSchema<NPC>(); // NPC 列表
    @type({map: Player}) players = new MapSchema<Player>();

    addPlayer(sessionId: string, name: string, x: number, y: number, hp: number, status: string) {
        const player = new Player(sessionId, name, x, y, hp, status);
        this.players.set(sessionId, player);
    }

    removePlayer(sessionId: string) {
        this.players.delete(sessionId);
    }

    updatePlayerPosition(sessionId: string, x: number, y: number) {
        if (this.players.has(sessionId)) {
            this.players.get(sessionId)!.x = x;
            this.players.get(sessionId)!.y = y;
        }
    }
}
